package com.nlx.notes.module.controller.loan;

import com.nlx.notes.module.bean.dto.loan.LoanBorrowerQueryDTO;
import com.nlx.notes.module.bean.dto.loan.LoanBorrowerSaveDTO;
import com.nlx.notes.module.bean.vo.loan.BorrowerInfoVO;
import com.nlx.notes.module.core.util.JSONUtils;
import com.nlx.notes.module.service.loan.IBorrowerInfoService;
import com.nlx.notes.support.context.UserHolder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 借款人信息 前端控制器
 * </p>
 *
 * @author nlx
 * @since 2025-10-25
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/borrowerInfo")
public class BorrowerInfoController {


    final IBorrowerInfoService borrowerInfoService;

    @GetMapping(value = "/list")
    public List<BorrowerInfoVO> list(LoanBorrowerQueryDTO loanBorrowerQueryDTO){
        Long userId = UserHolder.getUserContext().getId();
        loanBorrowerQueryDTO.setUserId(userId);
        log.info("查询当前用户的价款人信息：{}", loanBorrowerQueryDTO);
        return borrowerInfoService.listByCondition(loanBorrowerQueryDTO);
    }


    @PostMapping(value = "/save")
    public BorrowerInfoVO saveBorrower(@RequestBody  LoanBorrowerSaveDTO loanBorrowerSaveDTO){
        Long userId = UserHolder.getUserContext().getId();
        loanBorrowerSaveDTO.setUserId(userId);
        log.info("新增借款人信息：{}", JSONUtils.toString(loanBorrowerSaveDTO));
        return borrowerInfoService.saveBorrower(loanBorrowerSaveDTO);
    }


}
